﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Csla.Core;
using Csla.Wpf;
using Itenso.Windows.Input;

using OpenExpressApp.Command;
using OpenExpressApp.MetaModel;
using OpenExpressApp.Module;
using OpenExpressApp.Module.WPF;
using OpenExpressApp.Module.WPF.Templete;
using OpenExpressApp.Template;
using OpenExpressApp.Types;
using OpenExpressApp.WPF.Controls;

namespace OpenExpressApp.WPF.Templete
{
    /// <summary>
    /// Interaction logic for ListDetailForm.xaml
    /// </summary>
    public partial class ListDetailForm : WindowTemplateBase
    {
        private DetailObjectView _detailView;

        private ListDetailFormController _controller;

        public ListDetailForm(Type boType)
            : base(boType)
        {
            InitializeComponent();

            this._detailView = new DetailObjectView(boType);

            this.ListView.DetailView = this._detailView;
            this._detailView.ListView = this.ListView;

            this._controller = new ListDetailFormController(this);

            if (this.HasQueryPanel() == false)
            {
                this.ListView.DataLoader.AsyncGetObject();
            }
        }

        public override IFrameController Controller
        {
            get
            {
                return this._controller;
            }
        }

        public override ModuleType ModuleType
        {
            get
            {
                return ModuleType.Bill;
            }
        }

        /// <summary>
        /// 布局查询面板
        /// </summary>
        public override void LayoutQueryPanel()
        {
            LayoutQueryPanel(this.ListView, queryPane, dcCondition, dcNavigate);

            //自动隐藏查询面板
            if (ApplicationModel.GetBusinessObjectInfo(RootEntityType).AutoHideQueryPane)
            {
                queryPane.GetManager().ToggleAutoHide(queryPane);
            }
        }

        public override object GetRegion(string regionName)
        {
            switch (regionName)
            {
                case ViewRegionNames.ListRegion:
                    return listRegion;
                case ViewRegionNames.ConditionQueryRegion:
                    return conditionQueryRegion;
                case ViewRegionNames.NavigateQueryRegion:
                    return navigateQueryRegion;
                case ViewRegionNames.DetailRegion:
                    return detailRegion;
                case ViewRegionNames.MainToolBar:
                    return mainToolBar;
                case ViewRegionNames.Pads:
                    return pads;
                default:
                    return null;
            }
        }
    }
}